/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014 abel533@gmail.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package com.qgs.waf.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qgs.waf.mapper.DeviceMapper;
import com.qgs.waf.model.Device;
import com.qgs.waf.service.ZbksDeviceService;
import com.qgs.waf.util.JSonUtil;

/**
 * @author carl
 */
@Service(value="zbksDeviceServiceImpl")
public class ZbksDeviceServiceImpl implements ZbksDeviceService {
	@Resource
	private DeviceMapper deviceMapper;

	@Override
	public String select() {
		List<Device> ls = deviceMapper.select(new Device());
		return JSonUtil.object2JSon(ls);
	}

	@Override
	public String attackTrend(String begin, String end, String province, String industry) {
		List<Map<String, Object>> cs = deviceMapper.attackTrend(begin, end, province, industry);
		return JSonUtil.object2JSon(cs);
	}

	@Override
	public String attackSourceRanking(int pn, int ps, String begin, String end, String province, String industry) {
		PageHelper.startPage(pn, ps);
		List<Map<String, Object>> ls = deviceMapper.attackSourceRanking(begin, end, province, industry);
		// 用PageInfo对结果进行包装
		PageInfo page = new PageInfo(ls);
		return JSonUtil.object2JSon(page);
	}

	@Override
	public String attackPreview(int pn, int ps, String begin, String end, String province, String industry) {
		PageHelper.startPage(pn, ps);
		List<Map<String, Object>> ls = deviceMapper.attackPreview(begin, end, province, industry);
		// 用PageInfo对结果进行包装
		PageInfo page = new PageInfo(ls);
		return JSonUtil.object2JSon(page);
	}

	@Override
	public String attackOriginalData(int pn, int ps, String table, String begin, String end, String province, String industry,String wafid) {
		PageHelper.startPage(pn, ps);
		List<Map<String, Object>> ls = deviceMapper.attackOriginalData(table, begin, end, province, industry,wafid);
		// 用PageInfo对结果进行包装
		PageInfo page = new PageInfo(ls);
		return JSonUtil.object2JSon(page);
	}
}
